import java.lang.reflect.Field;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-03-31
 * Time: 17:30
 */

/**\
 * 反射私有属性反射私有属性
 */
public class Demo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException {
        Class c3=null;
        c3=Class.forName("Student");
        Field field =c3.getDeclaredField("name");
        field.setAccessible(true);
        Object object= c3.newInstance();
        Student student=(Student) object;
          field.set(student,"忘我");
          String name=(String) field.get(student);
        System.out.println(name);
     }
}
